import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/views/login/Login'
import Home from '@/views/home/Home'
import Hello from '@/views/hello/Hello'
import DormManager from '@/views/dorm-manager/DormManager.vue'
import Violation from '@/views/violation/Violation.vue'
import LeaveManager from '@/views/leave-manager/LeaveManager.vue'
import PerManager from '@/views/per-manager/perManager.vue'
import DataSummary from '@/views/data-Summary/DataSummary.vue'
import StudentServer from '@/views/student-server/studentServer'
import DormManagerDetail from '@/views/dorm-manager/DormManagerDetail.vue'


import User from '@/views/user/User.vue'
import { getToken } from "@/utils/auth";
// import ArticleUpdate from '@/views/article-manager/ArticleUpdate'
// import CreateArticle from '@/views/article-manager/CreateArticle'
// import CreateUser from '@/views/user/CreateUser'
// import ArticleType from '@/views/article-manager/ArticleType'
// import CreateArticleType from '@/views/article-manager/CreateArticleType'

import Vant from 'vant';
import 'vant/lib/index.css';

Vue.use(Vant);
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login,
    },
    {
      path: '/studentServer',
      name: 'studentServer',
      component: StudentServer,
    },
    {
      path: '/home',
      name: 'Home',
      component: Home,
      children: [
      {
          path: '/hello',
          name: 'Hello',
          component: Hello
        },
        {
          path: '/user',
          name: 'User',
          component: User
        },
        {
          path: '/dorm-manager',
          name: 'DormManager',
          component: DormManager,
          children:[{
            path: '/dorm-manager-detail',
            name: 'DormManagerDetail',
            component: DormManagerDetail,
          }]
        }, 
        {
          path: '/violation',
          name: 'Violation',
          component: Violation
        },
        {
          path: '/leave-manager',
          name: 'LeaveManager',
          component: LeaveManager
        },
        {
          path: '/per-manager',
          name: 'perManager',
          component: PerManager
        },
        {
          path: '/data-Summary',
          name: 'DataSummary',
          component: DataSummary
        }
      ]
    }]
  })
  const routesM = [{
    path: '/studentServer',
      name: 'studentServer',
      component: StudentServer,
  }]
  // if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
  //   routes = routesM
  //   } else {
  //   routes = router
  //   }
router.beforeEach((to, from, next) => {
  //检查用户是否登陆
  let isLogin = getToken();
  if (isLogin) {
    next();
  } else {
    if (to.fullPath == "/Login") { 
      next();
    } else if (to.fullPath === '/') {
      next();
    } else {
      //跳转到登陆页面
      next('/');
    }
  }
})

export default router